<template>
    <div class="list" ref="wrapper">
        <div>
            <div class="area">
                <div class="title">当前位置</div>
                <div class="btn-list">
                    <div class="btn-wrapper">
                        {{this.$store.state.city}}
                    </div>
                    
                </div>
            </div>
            <div class="area">
                <div class="title">热门城市</div>
                <div class="btn-list">
                    <div 
                        class="btn-wrapper" 
                        v-for="item of hotCities" 
                        :key="item.id"
                        @click="cityChange(item.name)"
                        >
                        {{item.name}}
                    </div>
                </div>
            </div>
            <div class="area" v-for="(item,key) of cities" :key="key" :ref="key">
                <div class="title site">{{key}}</div>
                <div class="city-list">
                    <div 
                        class="list-item" 
                        v-for="site of item" 
                        :key="site.id"
                        @click="cityChange(site.name)"
                        >{{site.name}}</div>
                </div>
            </div>
        </div>
    </div> 
</template>
<script>
import Bscroll from 'better-scroll'
export default {
    name:'CityList',
    props:{
        hotCities:Array,
        cities:Object,
        letter:String
    },
    methods:{
        cityChange(city){
            this.$store.commit('changeCity',city)
            this.$router.push('/')
        }
    },
    mounted () {
    this.scroll = new Bscroll(this.$refs.wrapper)
    },
    watch:{
        letter(){
            if(this.letter){
                const el = this.$refs[this.letter][0]
                this.scroll.scrollToElement(el)
            }
        }
    }
}
</script>
<style lang='stylus' scoped>
    .list
        position:absolute
        overflow:hidden
        top:1.6rem
        left :0
        right:0
        bottom:0
        margin-bottom:40%
        .area
            margin-top:.25rem
            .title
                line-height: .44rem
                padding:.1rem .2rem
                color :#999
                font-size :.34rem
            .site
                background:#f5f5f5
            .btn-list
                width:100%
                overflow :hidden
                padding :.1rem .6rem 0 .1rem
                .btn-wrapper
                    width:20%
                    margin:.1rem
                    line-height :.6rem
                    float :left
                    text-align :center
                    border-radius:.05rem
                    border:.005rem solid #23cc77
            .city-list
                .list-item
                    width:95%
                    margin:0 auto
                    line-height :.76rem
                    border-bottom:.005rem solid #eee
</style>
